{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <form class="mb-20" method="get" action="{:\\think\\Url::build($Request.action)}">
        <input type="text" class="input-text" style="width:250px" placeholder="产品id（多个请逗号隔开）" name="sales_id" value="{$Request.param.sales_id}">
        <input type="text" class="input-text" style="width:250px" placeholder="订单号" name="order_id" value="{$Request.param.order_id}">
        <input type="text" class="input-text" style="width:250px" placeholder="预订人" name="booking_people_name" value="{$Request.param.booking_people_name}">
        <input type="text" class="input-text" style="width:250px" placeholder="预订人手机" name="booking_people_phone" value="{$Request.param.booking_people_phone}">

        <input type="text" class="input-text Wdate  mb-5"  autocomplete="off" style="width:250px" placeholder="下单日期" name="ctime" value="{$Request.param.ctime}" {literal} onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" {/literal} >
        <input type="text" class="input-text Wdate  mb-5"  autocomplete="off" style="width:250px" placeholder="出行日期" name="date1" value="{$Request.param.date1}" {literal} onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" {/literal} >
        <input type="text" class="input-text" style="width:250px" placeholder="skuid（多个请逗号隔开）" name="skuid" value="{$Request.param.skuid}">


        <div class="select-box" style="width:250px">
            <select name="order_status" class="select">
                <option value="">选择订单状态</option>
                {volist name=":config('order_status')" id="order_statu"}
                <option value="{$key}">{$order_statu}</option>
                {/volist}
            </select>
        </div>
        <div class="select-box" style="width:250px">
            <select name="isrefund" class="select">
                <option value="">选择是否退款</option>
                <option value="0">不退款</option>
                <option value="1">退款</option>
            </select>
        </div>
        <div class="select-box" style="width:250px">
            <select name="platform" class="select">
                <option value="">选择平台</option>
                {foreach $platform as $pvo}
                <option value="{$pvo.platform_name}">{$pvo.name}</option>
                {/foreach}
            </select>
        </div>
        <!--新增已开发票和未开发票搜索框-->
        <div class="select-box" style="width:250px">
            <select name="invoice" class="select">
                <option value="1">选择是否开发票</option>
                <option {if ($Request.param.invoice == 2)} selected {/if} value="2">已开发票</option>
                <option {if ($Request.param.invoice == 3)} selected {/if} value="3">没有开发票</option>
            </select>
        </div>
        <!--<div class="select-box" style="width:250px">-->
        <!--<select name="allot_end" class="select">-->
        <!--<option value="">选择是否已分配完成</option>-->
        <!--<option value="0">未分配完成</option>-->
        <!--<option value="1">已分配完成</option>-->
        <!--</select>-->
        <!--</div>-->
        <button type="submit" class="btn btn-success" id="realname_btn" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
    </form>

    <?php use think\Db;?>
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            {tp:menu menu="add,forbid,resume,delete,recyclebin" /}
            <!--<a class="btn btn-primary radius mr-5"   href="{:url('/admin/order/export_to_excel',$searchCondition)}" >excel导出</a>-->
            <a class="btn btn-primary radius mr-5" id="sou" href="{:url('/admin/order/export_to_excel',$searchCondition)}" >excel导出</a>
            <a class="btn btn-primary radius mr-5" id="xuan" style="display: none;"  href="javascript:;" onclick="xuan()">excel导出</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="th" /}
            <th width="70">是否已开发票</th>
            <th width="70">平台</th>
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr class="text-c">
            {include file="td" /}
            <td class="f-14">
                {switch $vo.invoice}
                    {case value = "3"}未开发票{/case}
                    {case value = "2"}已开发票{/case}
                {/switch}
            </td>
            <td class="f-14">
                <?php
                    if($platform){
                        foreach($platform as $k=>$v){
                if($v['platform_name'] == $vo['platform']){
                $plate = $v['name'];
                }
                }
                }else{
                $plate = '';
                }
                ?>
                <?php echo $plate;?>
            </td>
            <td class="f-14">
                <!--<a href="javascript:;" onclick="agree('{$vo.id}')" class="label label-success radius" title="退款">退款</a>-->
                {$vo.status|show_status=$vo.id}
                {tp:menu menu='sedit' /}
                {tp:menu menu='sdelete' /}
                {php}
                $exceptional_orders=Db::name("exceptional_order")->where('oid',$vo['id'])->where('solve',false)->select();
                {/php}
                {if condition="$exceptional_orders"}
                <a title="编辑选项" href="javascript:;" onclick="layer_open('编辑选项','/admin/order/exceptional/oid/{$vo.id}')" style="text-decoration:none" class="ml-5 label label-warning radius">异常信息</a>
                {/if}
                {switch $vo.invoice}
                    {case value="3"}
                    <a style="text-decoration:none" onclick="invoice(2,'/admin/order/invoice/order_id/{$vo.id}')" href="javascript:;" title="已开发票" class="ml-5 label label-warning radius">确认开发票</a>
                    {/case}
                {/switch}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>

{/block}
{block name="script"}

<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script>

    //开发票按钮
    function invoice(val,url) {
        $.post(url,{invoice: val},function (data) {
            if (data.msg) {
                layer.msg(data.msg, {
                    time: 2000, //2s后自动关闭
                }, function () {
                    //关闭后刷新
                    location.reload();
                });
            }else{
                layer_open('确认开发票','/admin/pub/role/id/1')
            }
        });
    }

    function agree(id) {
        $.ajax({
            type: 'POST',
            url: "/admin/order/refund?id="+id,
            data: null,
            success: function (re){
                layer.msg(re.msg, {
                    time: 2000, //2s后自动关闭
                },function () {
                    //关闭后刷新
                    location.reload();
                });
            },
        });
    }
    $(function () {
        $("[name='isrefund']").find("[value='{$Request.param.isrefund}']").attr("selected", true);
        $("[name='order_status']").find("[value='{$Request.param.order_status}']").attr("selected", true);
        $("[name='platform']").find("[value='{$Request.param.platform}']").attr("selected", true);
    })

    //全选
    $('#checkAlls').bind("click", function () {
        $("input[name='id[]']").prop("checked",this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked
        if (sonChecked && allChecked){
            $('#xuan').css('display','inline') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        }else{
            $('#xuan').css('display','none')
            $('#sou').css('display','inline')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    });

    // 单选
    $("input[name='id[]']").bind('click', function () {
        var radioData =  $("input:checked[name='id[]']");
        // 选择数据的长度
        var len = radioData.serializeArray().length;
        if (len > 0) {
            $('#xuan').css('display','inline') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display','none')
            $('#sou').css('display','inline')
            $('#checkAlls').prop('checked',false); // 取消选择全选按钮
        }
        // console.log('你点击了单选')
        // console.log('点击的结果为：', this.checked)
        // console.log('你选择的数据是', radioData.serializeArray())
        // console.log('你选择的数据长度是',len)
    });

    function xuan() {
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        dataArr.push({name: 'search',value: 'isallot'})
        // console.log('选择的数据是', checkData.length)
        // console.log('选择的数据是', checkData.serializeArray())
        // console.log('选择的数组是', dataArr)
        $.ajax({
            type: 'post',
            url: '/admin/order/export_to_excel',
            data: dataArr,
            success: function (res) {
                if (res.code == 5){
                    // console.log('data', res);
                    location.href = res.msg; // 下载文件
                    // 删除文件
                    unclinkFile(res.msg)
                    layer.msg('导出数据成功');
                } else {
                    layer_open('excel导出数据','/admin/pub/role/id/1')
                }
            }
        });
    }
    var  value = 1;
    setTimeout(unclinkFile,1200000,value); // 延迟20分钟1200000
    // 15分钟后删除文件-900000
    function unclinkFile(val) {
        console.log(val)
        setTimeout(function () {
            // 删除文件
            $.ajax({
                type: 'post',
                url: '/admin/order/del',
                data: {val:val},
                success: function (data) {
                    console.log('data', data)
                    if (data.code != 5) {
                        console.log('删除失败', data.msg)
                    }
                }
            })
        },120000,val);
    }
</script>
{/block}
